import os
import requests

def download_video(video_url, save_path):

    # 获取保存目录
    save_dir = os.path.dirname(save_path)

    # 如果目录不存在，则创建
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)

    # 发起 HTTP 请求获取视频内容
    response = requests.get(video_url, stream=True)
    response.raise_for_status()  # 检查请求是否成功

    # 写入文件到本地
    with open(save_path, 'wb') as file:
        for chunk in response.iter_content(chunk_size=8192):
            file.write(chunk)

    print(f"视频已下载到: {save_path}")

# 示例用法
if __name__ == "__main__":
    video_url = "https://minimax-algeng-chat-tts.oss-cn-wulanchabu.aliyuncs.com/audio%2Ftts-20250711115651-cpsYnHXR.mp3?Expires=1752292612&OSSAccessKeyId=LTAI5tGLnRTkBjLuYPjNcKQ8&Signature=bYeHnKQ9CTOdaMp%2BgIBUCeyUloM%3D"
    save_path = r"D:\aaaaazzz\union_project\union_project1\a.mp3"
    download_video(video_url, save_path)
